<%@page import="${basepackage}.app.model.*" %>
<#include "/macro.include"/> 
<#include "/custom.include"/> 
<#assign className = table.className>   
<#assign classNameLower = className?uncap_first> 
<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ include file="/commons/taglibs.jsp" %>

<title><fmt:message key="${className}.title"/></title>
<script type="text/javascript" >

$(".${classNameLower}").addClass("active").closest("ul").show().siblings("a").addClass("active");
	$(document).ready(function() {
		// 分页需要依赖的初始化动作
		addDatePicker('.form_date');
		addDateTimePicker('.form_datetime'); 
		addPaginator('#pagination', '<@jspEl 'page.thisPageNumber'/>','<@jspEl 'page.lastPageNumber'/>');
		
		<#list table.columns as column>
		<#if column.isSecondSelectionColumn>
		$("#${column.referenceSelectionObjectLower}Id").change(function(){
			var id = $("#${column.referenceSelectionObjectLower}Id").val();
			$.ajax({
				type: "POST",
				url: "<@jspEl "ctx"/>/${classNameLower}/get${column.referenceTable}ListBy${column.referenceSelectionObject}",
				data: {
					id: id
				},
				dataType: 'json',
				success: function(data){
						$("#${column.columnNameLower}").empty();
						$("#${column.columnNameLower}").append('<option value=""><fmt:message key="selection.label.pleaseselectone"/></option');
						$.each(data,function(index,object){
							$("#${column.columnNameLower}").append('<option value="' + object.id + '">' + object.name + '</option');
						})
				
				}
			})
		});

		</#if>
		</#list>

	});
</script>



<form:form action="<@jspEl "ctx"/>/${classNameLower}/list" modelAttribute="query" id="queryForm" name="queryForm" method="get" style="display: inline;">

	<fieldset> 
		<legend>搜索</legend>
		<div class="form-group">			

			<#list table.notPkColumns?chunk(2) as row>
			<div class="row offset4"> 				

				<#list row as column>
				<#if !column.htmlHidden>	
				<div class="col-md-2 col-xs-4"><label><fmt:message key="${className}.${column.columnNameLower}.title"/> </label> </div>
				
				<#if column.isDateColumn> 
				<div class="col-md-3 col-xs-8">  
				<fmt:message key="search.label.from"/>
					<div class="input-group date form_date" data-date-format="dd/mm/yyyy"> 
						<form:input path="${column.columnNameLower}Begin" id="${column.columnNameLower}Begin" cssClass="form-control" readonly="true"/>						
						<span class="input-group-addon"><span class="glyphicon glyphicon-remove"></span></span>
						<span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span></span>
					</div>
				<fmt:message key="search.label.to"/>
					<div class="input-group date form_date" data-date-format="dd/mm/yyyy"> 
						<form:input path="${column.columnNameLower}End" id="${column.columnNameLower}End" cssClass="form-control" readonly="true"/>
						<span class="input-group-addon"><span class="glyphicon glyphicon-remove"></span></span>
						<span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span></span>
					</div>   
				</div>
				<#elseif column.isTimestampColumn> 
				<div class="col-md-3 col-xs-8">  
					<fmt:message key="search.label.from"/>
					<div class="input-group date form_datetime" data-date-format="dd/mm/yyyy hh:ii"> 
						<form:input path="${column.columnNameLower}Begin" id="${column.columnNameLower}Begin" cssClass="form-control" readonly="true"/>						
						<span class="input-group-addon"><span class="glyphicon glyphicon-remove"></span></span>
						<span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span></span>
					</div>
					<fmt:message key="search.label.to"/>
					<div class="input-group date form_datetime" data-date-format="dd/mm/yyyy hh:ii"> 
						<form:input path="${column.columnNameLower}End" id="${column.columnNameLower}End" cssClass="form-control" readonly="true"/>
						<span class="input-group-addon"><span class="glyphicon glyphicon-remove"></span></span>
						<span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span></span>
					</div>   
				</div>
				<#elseif column.isReferenceColumn>
				<div class="col-md-3 col-xs-8">  
				    <form:select path="${column.columnNameLower}" cssClass="form-control" id="${column.columnNameLower}">
				    	<form:option value=""><fmt:message key="selection.label.pleaseselectone"/></form:option>
				    	<#if !column.isSecondSelectionColumn>
				    	<form:options items="<@jspEl column.referenceTableLower +"List"/>" itemLabel="${column.referenceDisplayColumn}" itemValue="${column.referenceColumn}" />
				    	</#if>
				    </form:select>
				   </div>
				<#else>
				<div class="col-md-3 col-xs-8"> 
					<form:input path="${column.columnNameLower}" id="${column.columnNameLower}" cssClass="form-control" maxlength="${column.size}" class="${column.noRequiredValidateString}"/> 
				</div>
				</#if>


				</#if>
				</#list>

			</div>
			</#list>			

		</div>
	</fieldset>
	<div class="handleControl"> 
		<input type="submit" class="btn btn-primary" style="width:80px" value="<fmt:message key="navigation.button.query"/>" onclick="getReferenceForm(this).action='<@jspEl 'ctx'/>/${classNameLower}/list'"/>
		<input type="submit" class="btn btn-success" style="width:80px" value="<fmt:message key="navigation.button.new"/>" onclick="getReferenceForm(this).action='<@jspEl 'ctx'/>/${classNameLower}/create.do'"/>
		<input type="button" class="btn btn-danger" style="width:80px" value="<fmt:message key="navigation.button.delete"/>" onclick="batchDelete('<@jspEl 'ctx'/>/${classNameLower}/delete','items',document.forms.queryForm)"/>
	</div>


	<div class="panel-body">	
		<c:if test="<@jspEl 'page.lastPageNumber > 1'/>">
		<div class=" pull-right">
		<ul id="pagination"></ul>
		</div>
		</c:if>
		
		<input type="hidden" name="sortColumns" value="<@jspEl 'query.sortColumns'/>" />
		<input type="hidden" name="pageNumber" value="<@jspEl 'query.pageNumber'/>" />
		
		<div class="table-responsive">			
			<table class="table table-bordered table-striped table-condensed table-collapsible">
			  <thead>
				  
				  <tr>
					<th style="width:1px;"> </th>
					<th style="width:1px;"><input type="checkbox" onclick="setAllCheckboxState('items',this.checked)"></th>
					
					<#list table.columns as column> 
					<#if !column.htmlHidden && column.isEditable>
					<th><fmt:message key="${className}.${column.columnNameLower}.title"/> </th>
					</#if>
					</#list>
		
					<th><fmt:message key="navigation.label.operation"/></th>
				  </tr>
				  
			  </thead>
			  <tbody>
			  	  <c:forEach items="<@jspEl 'page.result'/>" var="item" varStatus="status">
			  	  
				  <tr>
					<td data-label="序号"><@jspEl 'page.thisPageFirstElementNumber + status.index'/></td>
					<td><input type="checkbox" name="items" value="<@generateIdQueryString/>"></td>
					
					<#list table.columns as column>
					<#if !column.htmlHidden && column.isEditable>
					<td data-label="<fmt:message key="${className}.${column.columnNameLower}.title"/>"><#rt>
						<#compress>
						<#if column.isReferenceColumn>
						<c:out value='<@jspEl "item."+column.referenceTableLower+"."+column.referenceDisplayColumn/>'/>&nbsp;
						<#else>
						<c:out value='<@jspEl "item."+column.columnNameLower/>'/>&nbsp;					
						</#if>
						</#compress>
					<#lt></td>
					</#if>
					</#list>
					<td data-label="<fmt:message key="navigation.label.operation"/>">
						<a href="<@jspEl 'ctx'/>/${classNameLower}/show?<@generateIdQueryString/>" class="btn btn-info"><fmt:message key="navigation.button.view"/></a>&nbsp;&nbsp;&nbsp;
						<a href="<@jspEl 'ctx'/>/${classNameLower}/edit?<@generateIdQueryString/>" class="btn btn-warning"><fmt:message key="navigation.button.edit"/></a>
					</td>
				  </tr>
				  
			  	  </c:forEach>
			  </tbody>
			</table>
		</div>
	</div>
</form:form>



<#macro generateIdQueryString>
	<#if table.compositeId>
		<#assign itemPrefix = 'item.id.'>
	<#else>
		<#assign itemPrefix = 'item.'>
	</#if>
<#compress>
		<#list table.compositeIdColumns as column>
			<#t>${column.columnNameLower}=<@jspEl itemPrefix + column.columnNameLower/>&
		</#list>				
</#compress>
</#macro>